package com.sy.musicapp.ui.home

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.sy.musicapp.model.Playlist
import com.sy.musicapp.ui.common.MyCard
import com.sy.musicapp.ui.common.PlaylistItem
import com.sy.musicapp.ui.theme.MusicAppTheme

/**
 * 歌单卡片组件
 * @author SY
 * @since 2022-02-07 21:36
 **/
@Composable
fun PlaylistCard(
    playlists: List<Playlist>,
    onSelectItem: (Int) -> Unit,
    addPlaylist: (String) -> Unit,
    delPlaylist: (String) -> Unit
) {
    MyCard(title = "歌单", littleContent = {
//        Icon(
//            imageVector = Icons.Rounded.Add,
//            contentDescription = null,
//            modifier = Modifier.clickable {
//                addPlaylist()//TODO 新建歌单名
//            },
//            tint = Global.colors.onPrimary
//        )
    }, content = {
        LazyColumn(
            modifier = Modifier.fillMaxWidth(1f),
            contentPadding = PaddingValues(horizontal = 5.dp, vertical = 10.dp),
            verticalArrangement = Arrangement.spacedBy(10.dp)
        ) {
            itemsIndexed(playlists, { _: Int, item: Playlist -> item.id }) { index, playlist ->
                PlaylistItem(
                    folder = playlist,
                    itemClick = {
                        onSelectItem(index)
                    },
                    itemDel = {
                        delPlaylist(it)
                    }
                )
            }
        }
    })
}

@Preview
@Composable
fun MusicFolderPrev() {
    MusicAppTheme {
        PlaylistCard(Playlist.Empty, addPlaylist = {}, delPlaylist = {}, onSelectItem = {})
    }
}

@Preview
@Composable
fun MusicFolderPrevDark() {
    MusicAppTheme(darkTheme = true) {
        PlaylistCard(Playlist.Empty, addPlaylist = {}, delPlaylist = {}, onSelectItem = {})
    }
}